import 'package:base_moudle/index.dart';
import 'package:cached_network_image/cached_network_image.dart';

import '../../../models/data_model/HyWorkModel.dart';
import '../../../new_paltform/define/hy_header.dart';

const double size_wh = 50;

class HyWorkAppImageButton extends StatelessWidget {
  HyWorkAppImageButton(
      {Key? key, required this.buttomItem, this.number = 0, this.onPressed})
      : super(key: key);

  ItemModel buttomItem;

  int number;
  VoidCallback? onPressed;

  @override
  Widget build(BuildContext context) {
    return Stack(alignment: Alignment.topCenter, children: [
      Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          if (buttomItem.iconName!.contains('http'))
            CachedNetworkImage(
              imageUrl: buttomItem.iconName!,
              width: size_wh,
              height: size_wh,
              fit: BoxFit.cover,
              errorWidget: (BuildContext c, String s, i) {
                return Container(
                  // margin: EdgeInsets.all(15),
                  width: size_wh, height: size_wh,
                  decoration: BoxDecoration(
                      color: zs_color_f2,
                      borderRadius: BorderRadius.circular(8)),
                );
              },
            ).intoContainer(
                color: Colors.white,
                margin: const EdgeInsets.only(top: 10, bottom: 10))
          else
            Image.asset(
              buttomItem.iconName,
              fit: BoxFit.fitWidth,
            ).intoContainer(
                height: size_wh,
                width: size_wh,
                margin: const EdgeInsets.only(top: 10, bottom: 10)),
          Expanded(
              child: ZsText(
            buttomItem.title,
            maxLines: 2,
            color: ColorHex('#333333'),
            fontSize: 13,
            textAlign: TextAlign.center,
          ))
        ],
      ),
      if (number != 0)
        Positioned(
            right: 10,
            top: 0,
            child: Container(
              // width: 20,
              // height: 20,
              padding: const EdgeInsets.fromLTRB(5, 2, 5, 2),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(20), color: Colors.red),
              child: Center(
                  child: Text(
                '${number > 99 ? '99+' : number}',
                style: const TextStyle(color: Colors.white, fontSize: 12),
              )),
            )),
    ]).intoGestureDetector(onTap: onPressed);
  }
}
